﻿/*
 *   MiscellaneousTests.cs
 *   Copyright (c) 2011 - BitFox Software and Ricardo Federico Villafañes
 *   Contact: federvillaf@hotmail.com
 *   
 *   Licensing: This product is covered by Microsoft Reciprocal License (MS-RL)
 *              see https://bitfoxeval.codeplex.com/license
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using BitFox.Evaluator;

namespace TestEvaluator
{
    /// <summary>
    /// Tests related, mainly, to functions that not belongs to any special category
    /// </summary>
    [TestClass]
    public class MiscellaneousTests
    {
        // The evaluator to use in tests
        Evaluator eval = new Evaluator();

        /// <summary>
        /// Empty constructor
        /// </summary>
        public MiscellaneousTests()
        {
        }

        /// <summary>
        /// The context under which tests are runned.
        ///</summary>
        public TestContext TestContext { get; set; }

        /// <summary>
        /// Test BETWEEN fox's function
        /// </summary>
        [TestMethod]
        public void TestBetween()
        {
            // Integers
            Assert.IsTrue((bool)eval.Compile("between(3, 2, 5)").Run());
            Assert.IsTrue((bool)eval.Compile("between(2, 2, 2)").Run());
            Assert.IsFalse((bool)eval.Compile("between(2, 3, 5)").Run());

            // Decimals
            Assert.IsTrue((bool)eval.Compile("between(3.4, 2.5, 5.0)").Run());
            Assert.IsTrue((bool)eval.Compile("between(2.0, 2.0, 2.0)").Run());
            Assert.IsFalse((bool)eval.Compile("between(2.1, 3.0, 5.4)").Run());

            // strings
            Assert.IsTrue((bool)eval.Compile("between('ac', 'ab', 'ad')").Run());
            Assert.IsTrue((bool)eval.Compile("between('ac', 'ac', 'ac')").Run());
            Assert.IsFalse((bool)eval.Compile("between('ac', 'ad', 'af')").Run());

            // Dates
            Assert.IsTrue((bool)eval.Compile("between({^2010/01/12}, {^2010/01/10}, {^2010/01/13})").Run());
            Assert.IsTrue((bool)eval.Compile("between({^2010/01/12}, {^2010/01/12}, {^2010/01/12})").Run());
            Assert.IsFalse((bool)eval.Compile("between({^2010/01/12}, {^2010/01/13}, {^2010/01/15})").Run());
        }

        /// <summary>
        /// Test IIF fox's function.
        /// </summary>
        [TestMethod]
        public void TestIif()
        {
            Assert.AreEqual(12, (int)eval.Compile("iif(.t., 12, 'hello')").Run());
            Assert.AreEqual("hello", (string)eval.Compile("iif(.f., 12, 'hello')").Run());
        }

        /// <summary>
        /// Test EVALUATE fox's function
        /// </summary>
        [TestMethod]
        public void TestEvaluator()
        {
            Assert.AreEqual(12m, Convert.ToDecimal(eval.Compile("evaluate('(20+4)/2')").Run()));
        }
    }
}
